package com.cloudxingkong.dianyinke.Student.Adapter;


import android.content.Context;
import android.graphics.Bitmap;
import android.util.LruCache;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.R;
import com.cloudxingkong.dianyinke.Student.bean.News;
import com.cloudxingkong.dianyinke.TeacherApp;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * 云星空科技
 * Created by ningfei on 2016/3/17.
 * 新闻资讯
 */
public class NewInformationAdapter extends BaseAdapter {
    private List<News> datas;
    private Context context;
    public NewInformationAdapter( List<News> datas, Context context) {

        this.datas = datas;
        this.context = context;

    }
    @Override
    public int getCount() {

        return datas == null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas == null ? null : datas.get(position-1);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView == null) {
            convertView = View.inflate(context, R.layout.newsinformation_item, null);
            holder = new ViewHolder();
            holder.tv_news_title = (TextView) convertView.findViewById(R.id.tv_news_title);
            holder.tv_news_content = (TextView) convertView.findViewById(R.id.tv_news_content);
            holder.tv_news_date = (TextView) convertView.findViewById(R.id.tv_news_date);
            holder.image_news_titlepic = (ImageView) convertView.findViewById(R.id.image_news_titlepic);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tv_news_title.setText(datas.get(position).getNewslist().getList().get(position).getTitle()+"");
        holder.tv_news_content.setText(datas.get(position).getNewslist().getList().get(position).getContent() + "");
        String serverTime = datas.get(position).getNewslist().getList().get(position).getDate()+"";
        String ts = serverTime.substring(0,10);
        holder.tv_news_date.setText(ts);
        if (datas.get(position).getNewslist().getList().get(position).getTitlepic() != null) {
            String imagerUrl = datas.get(position).getNewslist().getList().get(position).getTitlepic();

            ImageLoader.getInstance().displayImage(imagerUrl,holder.image_news_titlepic);
                }
                return convertView;
            }
            private class ViewHolder {
                TextView tv_news_title, tv_news_content, tv_news_date;
                ImageView image_news_titlepic;
            }
        public void clear () {
            datas.clear();
            notifyDataSetChanged();
        }
    }
